﻿using System;
using System.Collections.Generic;

using System.Text;
using System.Data;
using System.Data.Common;
using System.Collections;
using MSL.DataBase.Lib;

namespace MSL.DataBase
{
    /// <summary>
    /// 数据库接口
    /// </summary>
    internal interface IDbHelper
    {
        #region 事务

        void BeginTransaction();
        void CommitTransaction();
        void RollbackTransaction();
        #endregion

        #region 查询

        DbDataReader ExecReader(string commandTexts, bool isProc);
        DbDataReader ExecReader(string commandText, bool isProc, DbParameter[] parameters);
        DbDataReader ExecReader(string commandText, bool isProc, Hashtable parameters);

        T ExecScalar<T>(string commandText, bool isProc);
        T ExecScalar<T>(string commandText, bool isProc, DbParameter[] parameters);
        T ExecScalar<T>(string commandText, bool isProc, Hashtable parameters);
        object ExecScalar(string commandText, bool isProc);
        object ExecScalar(string commandText, bool isProc, DbParameter[] parameters);
        object ExecScalar(string commandText, bool isProc, Hashtable parameters);

        DataTable Query(string commandText, bool isProc);
        DataTable Query(string commandText, bool isProc, DbParameter[] parameters);
        DataTable Query(string commandText, bool isProc, Hashtable parameters);
        DataSet Query(string commandText, bool isProc, string srcTable);
        DataSet Query(string commandText, bool isProc, DbParameter[] parameters, string srcTable);
        DataSet Query(string commandText, bool isProc, Hashtable parameters, string srcTable);

        DataTable Query(string tableName, string primaryKey, string showFields, int pageIndex, int pageSize, string where, string sortBy, string groupBy, out int rowCount);
        #endregion

        #region 执行

        int ExecSql(string[] commandTexts);
        int ExecSql(string commandText, bool isProc);
        int ExecSql(string commandText, bool isProc, DbParameter[] parameters);
        int ExecSql(string commandText, bool isProc, Hashtable parameters);
        int ExecSql(List<SqlCmdTextAndParams> listCmdTextAndParams);
        int ExecSql(Hashtable sqlList);
        #endregion

        #region 存在性

        bool TableExists(string tableName);
        bool ColumnExists(string tableName, string columnName);
        bool Exists(string commandText);
        bool Exists(string commandText, Hashtable parameters);
        bool Exists(string commandText, bool isProc);
        bool Exists(string commandText, Hashtable parameters, bool isProc);
        #endregion

        #region 其它

        string GetDbTime();
        string PlusSign(params string[] values);
        void Open();
        void Close();
        #endregion

        #region 数据库管理

        bool RestoreDatabase(string dbName, string backfile);
        bool BackDataBase(string dbName, string dbFileName);
        bool CreateDataBase(string databaseName);
        bool DropDataBase(string databaseName);
        #endregion

        #region 批量操作

        void BulkInsert(DataTable table);
        void BatchUpdate(DataTable table);
        void BatchDelete(string sql, int batchSize = 1000, int interval = 1);
        void BatchUpdate(string sql, int batchSize = 1000, int interval = 1);
        #endregion
    }
}
